﻿<phone:PhoneApplicationPage
    x:Class="MultiPhotoChooser.MediaLibraryPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="LabelColor" TargetType="TextBlock">
            <Setter Property="Foreground" Value="White"/>
        </Style>
        <Style x:Key="TextSize" TargetType="Button">
            <Setter Property="FontSize" Value="16"/>
        </Style>

        <LinearGradientBrush x:Key="fadeBrush">
            <GradientStop Color="Red" Offset="0"/>
            <GradientStop Color="Gray" Offset="1"/>
        </LinearGradientBrush>

        <DataTemplate x:Key="PhotoItemTemplate">
            <StackPanel>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Image 
                        Width="100" Height="100" 
                        CacheMode="BitmapCache"
                        Source ="{Binding ThumbUrl}"
                        Stretch="UniformToFill"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                    </Image>
                </Grid>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="SavedItemTemplate">
            <StackPanel>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Image 
                        Width="100" Height="100" 
                        Margin="5"
                        CacheMode="BitmapCache"
                        Source ="{Binding ThumbUrl}"
                        Stretch="UniformToFill"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                    </Image>
                </Grid>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="AlbumTemplate">
            <StackPanel>
                <Grid Margin="5,5,5,5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Image
                        Width="500" Height="190" 
                        Stretch="UniformToFill"
                        CacheMode="BitmapCache"
                        Source ="{Binding ThumbUrl}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                    </Image>
                    <StackPanel Background="{StaticResource PhoneAccentBrush}" Height="60" VerticalAlignment="Bottom" Opacity="0.6">
                    </StackPanel>
                    <TextBlock Text="{Binding OriginalFileName}" 
                               Margin="15,140,0,0"
                               Foreground="{StaticResource PhoneForegroundBrush}"
                               FontSize="{StaticResource LongListSelectorGroupHeaderFontSize}"/>
                </Grid>
            </StackPanel>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}" Height="800" Width="480" Margin="0,10,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>
        <TextBlock Text="Media Library"  
                   Margin="10,0,0,0" 
                   Visibility="Collapsed"
                   Grid.Row="0" 
                   FontSize="{StaticResource PivotHeaderFontSize}" 
                   Foreground="#cc0000"/>
        <Grid Grid.Row="1" Visibility="Collapsed"
                        Margin="10" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
                
           
            <Button Name="btnCameraRoll" 
                    Click="Button_Click" 
                    CommandParameter="CameraRoll"
                    Content="CameraRoll"
                    BorderBrush="Gray"
                    Margin="-5"
                    Grid.Column="0"
                    Background="#cc0000"
                    BorderThickness="2"/>
            <Button Name="btnSavedPicture"
                    Margin="-5"
                    Click="Button_Click" 
                    CommandParameter="Saved Pictures"
                    Grid.Column="1"
                    Content="Saved Pictures"
                    BorderBrush="Gray"
                    BorderThickness="2"/>

        </Grid>
        
        <Grid Grid.Row="2" Margin="12,0,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            
            <phone:Pivot Title="" Name="pivot" SelectionChanged="pivot_SelectionChanged">
                <phone:PivotItem Margin="12,0,0,0">
                    <phone:PivotItem.Header>
                        <TextBlock Text="album" FontSize="{StaticResource PivotHeaderFontSize}" FontWeight="Bold" Foreground="{StaticResource PhoneAccentBrush}"/>
                    </phone:PivotItem.Header>
                        <!--ContentPanel - place additional content here-->
                    <phone:LongListSelector  
                        x:Name="lls_albums" 
                        Width="Auto"
                        LayoutMode="List"
                        GridCellSize="500,190" 
                        Visibility="Visible"
                        SelectionChanged="lls_albums_SelectionChanged"
                        ItemTemplate="{StaticResource AlbumTemplate}" />
                </phone:PivotItem>
                <phone:PivotItem Margin="24,0,0,0">
                    <phone:PivotItem.Header>
                        <TextBlock Name="AlbumNameHeader" Text="photo" FontSize="{StaticResource PivotHeaderFontSize}" FontWeight="Bold" Foreground="{StaticResource PhoneAccentBrush}"/>
                    </phone:PivotItem.Header>

                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <StackPanel Orientation="Vertical" 
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        Width="300">
                            <TextBlock Name="progressString" 
                           Text="Loading.." 
                           Visibility="Visible"
                           HorizontalAlignment="Center"
                           Foreground="{StaticResource PhoneAccentBrush}"
                           Margin="5"/>
                        </StackPanel>
                        <toolkit:LongListMultiSelector  
                                x:Name="lls_camera_roll" 
                                Width="Auto"
                                Margin="12,0,0,0"
                                LayoutMode="Grid" 
                                GridCellSize="100,100" 
                                ItemRealized="lls_camera_roll_ItemRealized"
                                EnforceIsSelectionEnabled="True"
                                Visibility="Visible"
                                SelectionChanged="lls_camera_roll_SelectionChanged"
                                ItemTemplate="{StaticResource PhotoItemTemplate}" />
                    </Grid>
                </phone:PivotItem>
                <phone:PivotItem Margin="24,0,0,0">
                    <phone:PivotItem.Header>
                        <TextBlock Text="selected" FontSize="{StaticResource PivotHeaderFontSize}" FontWeight="Bold" Foreground="{StaticResource PhoneAccentBrush}"/>
                    </phone:PivotItem.Header>
                    <!--ContentPanel - place additional content here-->
                    <phone:LongListSelector  
                            x:Name="lls_saved_picture" 
                            Width="Auto" 
                            Margin="12,0,0,0"
                            LayoutMode="Grid" 
                            GridCellSize="100,100" 
                            Visibility="Visible"
                            SelectionChanged="lls_saved_picture_SelectionChanged"
                            ItemTemplate="{StaticResource SavedItemTemplate}" />
                </phone:PivotItem>
            </phone:Pivot>

        </Grid>
       
        <Grid Grid.Row="3" Margin="12,0,12,0" VerticalAlignment="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="0" 
                       Grid.Column="0" 
                       Text="Picture Selected :" 
                       Visibility="Collapsed"
                       Margin="10" 
                       VerticalAlignment="Center"
                       Foreground="{StaticResource PhoneAccentBrush}"
                       FontSize="{StaticResource LongListSelectorGroupHeaderFontSize}"/>
            <TextBlock Grid.Row="0" 
                       Grid.Column="1" 
                       Name="tb_count" 
                       Visibility="Collapsed"
                       Text="0" 
                       Margin="5"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       Foreground="#cc0000"
                       FontSize="{StaticResource LongListSelectorGroupHeaderFontSize}"/>
            <Grid Grid.Row="0" Grid.Column="2" >
                <Button 
                        Name="btnSubmit" 
                        Content="submit" 
                        BorderThickness="2"
                        BorderBrush="{StaticResource PhoneAccentBrush}"
                        Margin="5,5,-5,5"
                        Click="btnSubmit_Click"/>
            </Grid>
        </Grid>
        
    </Grid>
    
</phone:PhoneApplicationPage>